﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace PropertyGrid控件
{
    //需要执行的方法列表
    public delegate void DoSomeFunction();
    class ShowInformation
    {
        public List<DoSomeFunction> doSome = new List<DoSomeFunction>();

        public ShowInformation()
        {
            doSome.Add(new DoSomeFunction(PrintA));
            doSome.Add(new DoSomeFunction(PrintB));
            doSome.Add(new DoSomeFunction(PrintC));
        }

        [DisplayName("名称")]
        [Editor(typeof(Information), typeof(System.Drawing.Design.UITypeEditor))]
        public string Name { get; set; }

        [Editor(typeof(Information), typeof(System.Drawing.Design.UITypeEditor))]
        public string Description { get; set; }

        public  void PrintA()
        {
            Console.WriteLine("PrintA");
        }

        public  void PrintB()
        {
            Console.WriteLine("PrintB");
        }

        public  void PrintC()
        {
            Console.WriteLine("PrintC");
        }

    }
    public class Information : UITypeEditor
        {
            public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
            {
                // 编辑属性值时，在右侧显示...更多按钮
                return UITypeEditorEditStyle.Modal;
            }

            public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
            {
                var edSvc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                if (edSvc != null)
                {
                    PropertiesForm PropertiesForm = new PropertiesForm();
                    // ShowDialog这种方式，可以弹出一个窗体来进行编辑
                    edSvc.ShowDialog(PropertiesForm);
                    value = PropertiesForm.Result;
                }
                return base.EditValue(context, provider, value);
            }
        }
}
